-
Notifications
You must be signed in to change notification settings - Fork 12.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improved lookahead for arrow functions. #203
Conversation
Fixes issue #34. Specifically: * We no longer automatically assume "()" is a function expression. It must be followed by an arrow, colon, or curly brace. * If an arrow is missing following a signature, but a curly brace is present, we assume the user forgot the arrow and try to parse the body anyway.
// We had "(" not followed by an identifier. This definitely doesn't | ||
// look like a lambda. Note: we could be a little more lenient and allow | ||
// "(public" or "(private". These would not ever actually be allowed, | ||
// but we could provide a good error message instead of bailing out. | ||
if (!isIdentifier()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did tihs comment move outside of the block that it is relevant to?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Felt like it would be more consistent since all the other comment blocks reside outside the checks. I'm feeling against it now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, with different phrasing, I think it might be fine.
Specifically where we have a full signature followed by an open curly brace.
var sig = parseSignature(SyntaxKind.CallSignature, SyntaxKind.ColonToken); | ||
parseExpected(SyntaxKind.EqualsGreaterThanToken); | ||
return sig; | ||
if (token === SyntaxKind.EqualsGreaterThanToken || token === SyntaxKind.OpenBraceToken) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good. could you add a comment here why having a colon isn't enogh. i.e. the ambiguity with:
a ? (b) : ...
thanks!
!!! ';' expected. | ||
~ | ||
!!! Cannot find name 'x'. | ||
!!! '=>' expected. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Improved lookahead for arrow functions.
Fixes issue #34.
Specifically: